package com.changgou.system.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * Created by roshellc on 2020/7/19.
 */
public class PortFilter implements Ordered,GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //请求进入过滤器
        System.out.println("请求进入第三个过滤器");


        //逻辑操作,打印一下该请求访问主机的端口号
        System.out.println(exchange.getRequest().getRemoteAddress().getPort());
        //放行操作
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 3;
    }
}
